package com.jcxy.controller;

import com.jcxy.pojo.Process;
import com.jcxy.pojo.User;
import com.jcxy.service.DeptService;
import com.jcxy.service.ProcessService;
import com.jcxy.util.PageBean;
import com.jcxy.util.ParamsDto;
import com.jcxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/newProcess")
public class NewProcessController {

    @Autowired
    private DeptService deptService;
    @Autowired
    private ProcessService processService;

    /**
     * 查询部门员工
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/getDeptStaffList.do")
    @ResponseBody
    public ResponseData getDeptStaffList(HttpServletRequest request){

        Map dto = ParamsDto.getDto(request.getParameterMap());

        PageBean pageBean = deptService.queryDeptStaffListByPage(dto,//查询条件
                Integer.valueOf(dto.get("page").toString()),//当前页
                Integer.valueOf(dto.get("limit").toString()));//页容量

        return pageBean.getResponseData();
    }

    /**
     * 添加部门基本信息
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/addProcess.do")
    public String addProcess(HttpServletRequest request) throws Exception{

        Map dto = ParamsDto.getDto(request.getParameterMap());

        //获取登录user对象
        User user = (User) request.getSession().getAttribute("user");
        dto.put("user_id",user.getUser_id());

        //获取流程类型：burse、evection、overtime、regular、holiday、resign
        String process_type = dto.get("process_type").toString();
        //判断流程类型
        if("burse".equals(process_type)){

            //添加费用报销流程
            processService.addBurseProcess(dto);
        }else if ("evection".equals(process_type)){

            //添加出差流程
            processService.addEvectionProcess(dto);
        }else if("overtime".equals(process_type)){

            //添加加班流程
            processService.addOvertimeProcess(dto);
        }else if("regular".equals(process_type)){

            //添加转正流程
            processService.addRegularProcess(dto);
        }else if("holiday".equals(process_type)){

            //添加请假流程
            processService.addHolidayProcess(dto);
        }else if("resign".equals(process_type)){

            //添加请假流程
            processService.addResignProcess(dto);
        }

        //将操作成功码存放在请求中，用于前端显示提示框
        request.setAttribute("editOption","200");

        return "processManage/newProcess";
    }
}
